package ude.univ.esiag.gon.uchiha.gui;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import ude.univ.esiag.gon.uchiha.data.DataObject;
import ude.univ.esiag.gon.uchiha.listener.TopicListener;
import ude.univ.esiag.gon.uchiha.register.Multicaster;
import ude.univ.esiag.gon.uchiha.topic.Topic;

public class TopicPanel extends JPanel implements TopicListener{
	private static final long serialVersionUID = 1L;
	private JTextArea area;
	private JPanel panel;
	public TopicPanel(JPanel panel) {
		this.panel = panel;
		area = new JTextArea(10, 10);
		add(area);
		setBorder(BorderFactory.createLineBorder(Color.black));
		this.panel.add(this);
	}
	public void modifiedCache(DataObject data) {
		String name = data.getTopicName();
		int index = name.indexOf(".");
		if(index != -1)
			name = name.substring(0, index);
		Topic topic1 = Multicaster.getInstance().getTopicByName(name);
		area.setText(topic1.toString());
	}
	public void modifiedTopic(Topic topic) {
		String name = topic.getName();
		int index = name.indexOf(".");
		if(index != -1)
			name = name.substring(0, index);
		Topic topic1 = Multicaster.getInstance().getTopicByName(name);
		area.setText(topic1.toString());
	}
}
